from sif import SIF_similarity
from word2vec import get_w2v


def confusion_matrix(predict, result):
    cm = {
        "00": 0,
        "01": 0,
        "10": 0,
        "11": 0
    }
    for i in range(len(label)):
        cm[str(label[i]) + str(predict[i])]+=1

    print("--"*20)
    print(" \t实际标签为正\t实际标签为负")
    print("\n预测标签为正\t%d\t%d"%(cm["11"], cm["01"]))
    print("\n预测标签为负\t%d\t%d"%(cm["10"], cm["00"]))
    print("\n准确率：%.4f"%((cm["11"]+cm["00"])/len(label)))

if __name__ == "__main__":
    file_path = "./data/train.txt"
    sen1_list, sen2_list, word_emb, word2id, word_freq, label = get_w2v(file_path)
    sif = SIF_similarity(word_freq, word_emb)
    result = sif.fit(sen1_list, sen2_list)
    result = [1 if i>=0.5 else 0 for i in result]
    confusion_matrix(result, label)